/**
 * 
 */
package com.tientrung.qlsv;

import java.util.Scanner;

import com.tientrung.qlsv.database.DataAccess;
import com.tientrung.qlsv.model.User;

/**
 * @author MtRol
 * 
 */
public class QLSV {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		showLoginScreen();
		// DataAccess data = DataAccess.getInstance();
		// if (data.checkLogin("trungnt", "tientrung")) {
		// System.out.println("login success ok");
		// } else {
		// System.exit(0);
		// }

	}

	private static User user;

	// hien thi thong tin ve man hinh dang nhap
	public static void showLoginScreen() {
		System.out.println("QUAN LY SINH VIEN");
		System.out.println("\nDang nhap");
		String username, password;
		Scanner input = new Scanner(System.in);
		System.out.println("user name: ");
		username = input.nextLine();
		System.out.println("password:");
		password = input.nextLine();

		user = DataAccess.getInstance().checkLogin(username, password);
		if (user == null) {
			System.exit(0);
		} else if (user.mType == User.TYPE_MANAGER) {
			showManagerScreen();

		} else if (user.mType == User.TYPE_TEACHER) {
			showTeacherScreen();
		} else if (user.mType == User.TYPE_USER) {
			showUserScreen();
		}
	}

	private static void showUserScreen() {
		while (true) {
			int i;
			System.out.printf("1.Dang ky mon hoc\n"
					+ "2.Xem danh sach nhung mon dang ky\n" + "3.Xem ho so\n"
					+ "4.Exit\n");
			Scanner input = new Scanner(System.in);
			i = input.nextInt();

			if (i == 1) {
				while (true) {
					int j;
					System.out.printf("1.xem danh sach mon\n" + "2.chon mon\n"
							+ "3.exit\n");
					j = input.nextInt();

					if (j == 1)
						DataAccess.getInstance().showListSubject();
					else if (j == 2) {
						int subjectId;
						String userId = user.mMaSV;
						System.out.println("nhap vao ma mon hoc");
						subjectId = input.nextInt();
						DataAccess.getInstance().insertSubject(userId,
								subjectId);
					}
					else break;
				}
			
			}
			
			else if(i==2)
			{
				DataAccess.getInstance().showListSubject();
			}
			else if(i==3)
			{
				System.out.printf(user.mName+user.mMaSV+user.mClass+user.mCountry+user.mUserName);
			}
				
			else break;
		}
	}

	private static void showTeacherScreen() {

		while (true) {
		
			int i;
			System.out.printf("1.Dang ky giang day\n"
					+ "2.Xem danh sach nhung mon dang ky\n" + "3.Xem ho so\n"
					+ "4.Exit\n");
			Scanner input = new Scanner(System.in);
			i = input.nextInt();

			if (i == 1) {
				while (true) {
					int j;
					System.out.printf("1.xem danh sach mon\n" + "2.chon mon\n"
							+ "3.exit\n");
					j = input.nextInt();

					if (j == 1)
						DataAccess.getInstance().showListSubject();
					else if (j == 2) {
						int subjectId;
						String userId = user.mMaSV;
						subjectId = input.nextInt();
						DataAccess.getInstance().insertSubject(userId,
								subjectId);
					}
					else break;
				}
			
			}
			
			else if(i==2)
			{
				DataAccess.getInstance().showListSubject();
			}
			else if(i==3)
			{
				System.out.printf(user.mName+user.mMaSV+user.mClass+user.mCountry+user.mUserName);
			}
				
			else break;
		}
	

	}

	private static void showManagerScreen() {

	}

	// hien thi menu lua chon cho sinh vien
	public static int getChoiseOfStudent() {

		return 0;
	}

	// hien thi menu lua chon cho giao vien
	public static int getChoiseOfTeacher() {

		return 0;
	}

	// hien thi menu lua chon cho Manager
	public static int getChoiseOfManager() {

		return 0;
	}
}
